package com.htl.exampro.course.controller;

import com.htl.exampro.base.model.PageResult;
import com.htl.exampro.base.model.ServerResponse;
import com.htl.exampro.course.pojo.query.CoursePageParam;
import com.htl.exampro.course.pojo.vo.ChapterVO;
import com.htl.exampro.course.pojo.vo.CourseVO;
import com.htl.exampro.course.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程控制器
 */
@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    /**
     * 获取课程列表
     */
    @PostMapping("/page")
    public ServerResponse<PageResult<CourseVO>> getCoursePage(@RequestBody CoursePageParam pageParam) {
        PageResult<CourseVO> result = courseService.getCoursePage(pageParam);
        return ServerResponse.success(result);
    }

    /**
     * 添加课程
     */
    @PostMapping("")
    public ServerResponse<Void> addCourse(@RequestBody CourseVO course) {
        courseService.addCourse(course);
        return ServerResponse.success();
    }

    /**
     * 获取课程详情
     */
    @GetMapping("/{id}")
    public ServerResponse<CourseVO> getChapter(@PathVariable("id") String id) {
        CourseVO course = courseService.getChapter(id);
        return ServerResponse.success(course);
    }

    /**
     * 更新课程
     */
    @PutMapping("")
    public ServerResponse<Void> updateCourse(@RequestBody CourseVO course) {
        courseService.updateCourse(course);
        return ServerResponse.success();
    }

    /**
     * 删除课程
     */
    @DeleteMapping("/{id}")
    public ServerResponse<Void> deleteCourse(@PathVariable("id") String id) {
        courseService.deleteCourse(id);
        return ServerResponse.success();
    }

    /**
     * 获取课程章节列表
     */
    @GetMapping("/{courseId}/chapters")
    public ServerResponse<List<ChapterVO>> getCourseChapters(@PathVariable("courseId") String courseId) {
        List<ChapterVO> chapters = courseService.getCourseChapters(courseId);
        return ServerResponse.success(chapters);
    }

    /**
     * 添加课程章节
     */
    @PostMapping("/chapter")
    public ServerResponse<Void> addCourseChapter(@RequestBody ChapterVO chapter) {
        courseService.addCourseChapter(chapter);
        return ServerResponse.success();
    }

    /**
     * 更新课程章节
     */
    @PutMapping("/chapter")
    public ServerResponse<Void> updateCourseChapter(@RequestBody ChapterVO chapter) {
        courseService.updateCourseChapter(chapter);
        return ServerResponse.success();
    }

    /**
     * 删除课程章节
     */
    @DeleteMapping("/chapter/{id}")
    public ServerResponse<Void> deleteCourseChapter(@PathVariable("id") String id) {
        courseService.deleteCourseChapter(id);
        return ServerResponse.success();
    }
} 